import Vue from 'vue';
import App from './App.vue';
import router from "./router";
import store from "./store";
import ElementUI from 'element-ui';
import "@/assets/iconfont/iconfont.css";
import 'element-ui/lib/theme-chalk/index.css';
import * as echarts from "echarts";
import VueResource from "vue-resource";
import './assets/styles/index.scss';
import './api/mock.js';



Vue.use(ElementUI);
Vue.use(VueResource);

Vue.config.productionTip = false;
Vue.prototype.$echarts = echarts;

//导航守卫
//登入next（判断localStorage是否存入token） 未登入跳转登录页
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token") || "";
  if (!token) {
    if (to.path === "/Login") {
      next();
    } else {
      next({ path: "/Login" });
    }
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
